package com.ruoyi.alarmmanagement.job;

import com.ruoyi.alarmmanagement.entity.TerminalWarn;
import com.ruoyi.alarmmanagement.entity.WarnStrategy;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;

/**
 * 大用户表压力数值突变预警
 * @author TsingYu
 * @version 1.0
 * @date 2024/8/15 14:47
 */
@Component("pressureMutationDb")
@Slf4j
public class PressureMutationDb extends BaseWarnJob{

    /**
     * 获取预警参数类型-大用户表压力数值突变预警
     *
     * @return 预警参数类型-大用户表压力数值突变预警
     */
    @Override
    protected String getWarnParamType() {
        return "2";
    }

    /**
     * 获取预警类型-阈值
     *
     * @return 预警类型-阈值
     */
    @Override
    protected int getWarnType() {
        return 3;
    }

    /**
     * 执行预警数据生成-大用户表压力数值突变预警
     *
     * @param date 生成指定日期的预警数据
     */
    @Override
    public void execute(Date date) {
        List<TerminalWarn> terminals = getWarnStrategyMapper().selectPressureMutationDb(date, getWarnParamType(), WarnStrategy.WARN_TARGET_TYPE_ELE);
        if (CollectionUtils.isEmpty(terminals)) {
            log.info("无大用户表压力数值突变预警信息");
            return;
        }
        boolean success = insertWarnBatch(terminals, getWarnType());
        if (success) {
            log.info(String.format("大用户表压力数值突变预警数据生成成功，共%d条", terminals.size()));
        }
    }
}
